package org.sang.controller.admin;

import com.alibaba.fastjson.JSON;
import org.sang.pojo.RespBean;
import org.sang.pojo.dto.MenuDTO;
import org.sang.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    private static final Logger logger = LoggerFactory.getLogger(MenuController.class);

    @Resource
    private MenuService menuService;

    @PostMapping("/addOne")
    public RespBean<Integer> addMenu(@RequestBody MenuDTO menuDTO){
        logger.info("addMenu_menuDTO={}", JSON.toJSONString(menuDTO));
        return menuService.addMenu(menuDTO);
    }

    @GetMapping("/list")
    public RespBean<List<MenuDTO>> allMenus(){
        return menuService.allMenus();
    }

    @GetMapping("/list/{roleId}")
    public RespBean<List<MenuDTO>> getMenusByRoleId(@PathVariable("roleId") Integer roleId){
        logger.info("getMenusByRoleId_roleId={}", roleId);
        return menuService.getMenusByRoleId(roleId);
    }
}
